package com.blb.educourseservice.controller;

import com.blb.common.entity.Course;
import com.blb.common.entity.ResponseResult;
import com.blb.educourseservice.service.CourseService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CourseController {

    @Resource
    private CourseService courseService;

    @GetMapping("/courses")
    public ResponseResult<List<Course>> getAllCourses(){
        List<Course> courses = courseService.getAllCourses();
        return ResponseResult.ok(courses);
    }

    @GetMapping("/course/{id}")
    public ResponseResult<Course> getCourseById(@PathVariable Long id){
        Course course = courseService.getCourseById(id);
        return ResponseResult.ok(course);
    }

    @GetMapping("/course-details/{id}")
    public ResponseResult<Course> getCourseDetailsById(@PathVariable Long id){
        Course course = courseService.getCourseDetailsById(id);
        return ResponseResult.ok(course);
    }

    @RequestMapping("/course/add-sales/{id}")
    public Course addCourseSales(@PathVariable Long id){
        return courseService.addCourseSales(id);
    }

    @RequestMapping("/course/reduce-sales/{id}")
    public Course reduceCourseSales(@PathVariable Long id){
        return courseService.reduceCourseSales(id);
    }
}
